package com.mervin.enums;

import com.mervin.convert.*;

/***************************************
 * @author: mervin
 * @Date: 2020-05-04 15:33
 * @Description: 字段枚举及类型转换器
 ***************************************/
public enum FieldTypeConvertEnum {

    /**
     * String类型
     */
    StringType("class java.lang.String", "String类型", new StringConvert()),
    /**
     * Integer类型
     */
    IntegerType("class java.lang.Integer", "Integer类型", new IntegerConvert()),
    IntType("int", "Integer类型", new IntegerConvert()),
    /**
     * Boolean类型
     */
    BooleanType("class java.lang.Boolean", "Boolean类型", new BooleanConvert()),
    /**
     * Date类型
     */
    DateType("class java.util.Date", "Date类型", new DateConvert()),
    /**
     * BigDecimal类型
     */
    BigDecimalType("class java.math.BigDecimal", "BigDecimal类型", new BigDecimalConvert()),
    ;


    FieldTypeConvertEnum(String type, String typeDesc, Convert convert) {
        this.type = type;
        this.typeDesc = typeDesc;
        this.convert = convert;
    }

    public static Convert getConvert(String type){
        for (FieldTypeConvertEnum fieldTypeConvertEnum: values()){
            if(fieldTypeConvertEnum.getType().equals(type)){
                return fieldTypeConvertEnum.getConvert();
            }
        }
        return null;
    }

    /**
     * 属性类型
     */
    private String type;

    /**
     * 属性类型描述
     */
    private String typeDesc;

    /**
     * 类型转换接口
     */
    private Convert convert;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getTypeDesc() {
        return typeDesc;
    }

    public void setTypeDesc(String typeDesc) {
        this.typeDesc = typeDesc;
    }

    public Convert getConvert() {
        return convert;
    }

    public void setConvert(Convert convert) {
        this.convert = convert;
    }
}
